package com.neteast.androidclient.contact.activity;

import java.util.ArrayList;
import java.util.Arrays;
import com.neteast.androidclient.contact.R;
import com.neteast.androidclient.contact.domain.ContactRowManager;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
/**
 * 主界面，包含两个按钮，点击按钮，装载对应的activity
 * @author tiangh
 * 2012-3-12 下午5:22:58
 */
public class MainActivity extends ActivityGroup implements OnClickListener {
    private LinearLayout container;
    public static ArrayList<String> phoneTypes=new ArrayList<String>();
	public static ArrayList<String> emailTypes=new ArrayList<String>();
	public static ArrayList<String> imTypes=new ArrayList<String>();
	public static ArrayList<String> locationTypes=new ArrayList<String>();
	public static ArrayList<String> allGroups=new ArrayList<String>();
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.main);
        init();
    }

	private void init() {
		container = (LinearLayout) findViewById(R.id.container);
		findViewById(R.id.btn_contact).setOnClickListener(this);
		findViewById(R.id.btn_me).setOnClickListener(this);
		phoneTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.phone_types)));
		emailTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.email_types)));
		imTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.im_types)));
		locationTypes.addAll(Arrays.asList(getResources().getStringArray(R.array.location_types)));
		container.addView(getLocalActivityManager().startActivity("contact", 
				new Intent(this,ContactActivity.class)
						.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
						.getDecorView());
	}


	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_contact:
			ContactRowManager.clearRowsCache();
			container.removeAllViews();
			container.addView(getLocalActivityManager().startActivity("contact", 
					new Intent(this,ContactActivity.class)
							.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
							.getDecorView());
			break;
		case R.id.btn_me:
			container.removeAllViews();
			container.addView(getLocalActivityManager().startActivity("me", 
					new Intent(this,MeActivity.class)
							.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
							.getDecorView());
			break;
		}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		phoneTypes.clear();
		emailTypes.clear();
		imTypes.clear();
		locationTypes.clear();
		ContactRowManager.clearRowsCache();
	}
}